package io.write_file;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @author haomin
 * @date 2022/05/09 20:06
 **/
public class WriteFile1 {
    public static void main(String[] args) throws IOException {
        try (OutputStream os = new FileOutputStream("src/io/read_file/hello.txt")){
            // 一个写一个
            os.write('h');
            os.write('e');

            // 一次写一行
            byte[] b = {'l','l','o'};
            os.write(b);
            // flush 缓存池
            os.flush();
        }

        try(OutputStream os = new FileOutputStream("src/io/read_file/hello.txt")){
            os.write('h');
            os.write('e');
            os.write('l');
            os.write('l');
            os.write('o');
            os.flush();
        }

        try(OutputStream os = new FileOutputStream("src/io/read_file/hello.txt")) {
            byte[] buf = new byte[]{'a', 'b', 'c', 'd'};
            os.write(buf);
            os.flush();
        }
    }
}